
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Bacalá
 */
public class Tank {

    private Image imagem = null;
    private int maxX, maxY, x, y;
    private int passoX = 6;

    public Tank(int maxX, int maxY) {
        this.maxX = maxX;
        this.maxY = maxY;
        try {
            imagem = Image.createImage("/tank.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }

    public void mexeD() {
        if (x < this.getMaxX()) {
            x += passoX;
        }
    }

    public void mexeE() {
        if (x > this.getMinX()) {
            x -= passoX;
        }
    }

    public void centraliza() {
        x = (this.maxX - this.getWidth()) / 2;
    }

    public int getPassoX() {
        return passoX;
    }

    public void setPassoX(int passoX) {
        this.passoX = passoX;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Image getImagem() {
        return imagem;
    }

    public int getWidth() {
        return 40;
    }

    public int getHeight() {
        return 5;
    }

    public int getMinY() {
        return this.getY() - this.getHeight() / 2;
    }

    public int getMaxY() {
        return this.getY() + this.getHeight() / 2;
    }

    public int getMinX() {
        return this.getX() - this.getWidth() / 2;
    }

    public int getMaxX() {
        return this.getX() + this.getWidth() / 2;
    }

    public void paint(Graphics g) {
        g.setColor(255, 0, 0);
        g.drawImage(this.imagem, x, y, Graphics.HCENTER | Graphics.VCENTER);
    }
}
